package kr.hkit.androidcomplete01.ch12;

import kr.hkit.androidcomplete01.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class ListViewXml extends Activity {
	private ArrayAdapter<CharSequence> adapter;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch12_listview);
		
		adapter = ArrayAdapter.createFromResource(
				this, R.array.country, android.R.layout.simple_list_item_1);
		ListView listView = (ListView) findViewById(R.id.list);
		
		listView.setAdapter(adapter);
		
		listView.setOnItemClickListener(mItemClickListener);
		/*listView.setChoiceMode(listView.CHOICE_MODE_SINGLE);
		listView.setDivider(new ColorDrawable(Color.RED));
		listView.setDividerHeight(5);*/
	}
	
	AdapterView.OnItemClickListener mItemClickListener = new AdapterView.OnItemClickListener() {

		@Override
		public void onItemClick(AdapterView<?> parent, View view, int position,
				long id) {
			StringBuilder sb = new StringBuilder();
			sb.append(parent.getCount() + "개\t");
			sb.append(view.getId() + "view Id\t");
			sb.append("position = " + position + " id = " + id);
			sb.append(adapter.getItem(position));
			Toast.makeText(ListViewXml.this, sb.toString(), Toast.LENGTH_LONG).show();
		}
	};
}
